package com.taoyibao.hongcanting.ui;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;

import com.taoyibao.hongcanting.event.EventMusic;
import com.taoyibao.hongcanting.utils.AppFrontBackHelper;
import com.taoyibao.hongcanting.utils.JPushUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * @author TangAnna
 * @description: 项目Application
 * @date :${DATA} 11:29
 */
public class HongApplication extends Application {

    public static Context mContext;//全局的Application
    public static HongApplication mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;
        mContext = getApplicationContext();
        //设置极光推送开启debug
        JPushUtils.setDebugMode();
        //初始化极光推送
        JPushUtils.init();

        AppFrontBackHelper appFrontBackHelper = new AppFrontBackHelper();
        appFrontBackHelper.register(this, new AppFrontBackHelper.OnAppStatusListener() {
            @Override
            public void onFront() {
                EventBus.getDefault().post(new EventMusic(true, false));
            }

            @Override
            public void onBack() {
                EventBus.getDefault().post(new EventMusic(true, true));
            }
        });
    }

    public static Context getContext() {
        return mContext;
    }

    public static HongApplication getInstance() {
        return mInstance;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //5.0以下的版本因为引用的包过多，实现多包问题
        MultiDex.install(this);
//        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
//            MultiDex.install(this);
//        }
    }

}
